﻿Imports System
Imports System.CodeDom
Imports System.Collections.Generic
Imports System.Diagnostics.CodeAnalysis
Imports System.Globalization
Imports System.Reflection
Imports System.Text
Imports System.Workflow.ComponentModel.Compiler

Namespace System.Workflow.Activities.Rules
    Friend Class BinaryExpression
        Inherits RuleExpressionInternal
        ' Methods
        Friend Overrides Sub AnalyzeUsage(ByVal expression As CodeExpression, ByVal analysis As RuleAnalysis, ByVal isRead As Boolean, ByVal isWritten As Boolean, ByVal qualifier As RulePathQualifier)
            Dim expression2 As CodeBinaryOperatorExpression = DirectCast(expression, CodeBinaryOperatorExpression)
            Dim info As RuleBinaryExpressionInfo = [TryCast](analysis.Validation.ExpressionInfo(expression2),RuleBinaryExpressionInfo)
            If (Not info Is Nothing) Then
                Dim methodInfo As MethodInfo = info.MethodInfo
                If (Not methodInfo Is Nothing) Then
                    Dim attributedExprs As New List([Of] CodeExpression)
                    Dim argExprs As New CodeExpressionCollection
                    argExprs.Add(expression2.Left)
                    argExprs.Add(expression2.Right)
                    Dim targetExpr As CodeExpression = New CodeTypeReferenceExpression(methodInfo.DeclaringType)
                    analysis.AnalyzeRuleAttributes(methodInfo, targetExpr, qualifier, argExprs, methodInfo.GetParameters, attributedExprs)
                End If
            End If
            RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Left, True, False, Nothing)
            RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Right, True, False, Nothing)
        End Sub

        Friend Overrides Function Clone(ByVal expression As CodeExpression) As CodeExpression
            Dim expression2 As CodeBinaryOperatorExpression = DirectCast(expression, CodeBinaryOperatorExpression)
            Return New CodeBinaryOperatorExpression { _
                .[Operator] = expression2.[Operator], _
                .Left = RuleExpressionWalker.Clone(expression2.Left), _
                .Right = RuleExpressionWalker.Clone(expression2.Right) _
            }
        End Function

        <SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")> _
        Friend Overrides Sub Decompile(ByVal expression As CodeExpression, ByVal stringBuilder As StringBuilder, ByVal parentExpression As CodeExpression)
            Dim str3 As String
            Dim flag As Boolean = False
            Dim childExpr As CodeBinaryOperatorExpression = DirectCast(expression, CodeBinaryOperatorExpression)
            If (childExpr.Left Is Nothing) Then
                Dim exception As New RuleEvaluationException(String.Format(CultureInfo.CurrentCulture, Messages.NullBinaryOpLHS, New Object() { childExpr.[Operator].ToString }))
                exception.Data.Item("ErrorObject") = childExpr
                Throw exception
            End If
            If (childExpr.Right Is Nothing) Then
                Dim exception2 As New RuleEvaluationException(String.Format(CultureInfo.CurrentCulture, Messages.NullBinaryOpRHS, New Object() { childExpr.[Operator].ToString }))
                exception2.Data.Item("ErrorObject") = childExpr
                Throw exception2
            End If
            Select Case childExpr.[Operator]
                Case CodeBinaryOperatorType.Add
                    str3 = " + "
                    Exit Select
                Case CodeBinaryOperatorType.Subtract
                    str3 = " - "
                    Exit Select
                Case CodeBinaryOperatorType.Multiply
                    str3 = " * "
                    Exit Select
                Case CodeBinaryOperatorType.Divide
                    str3 = " / "
                    Exit Select
                Case CodeBinaryOperatorType.Modulus
                    str3 = " % "
                    Exit Select
                Case CodeBinaryOperatorType.IdentityInequality
                    str3 = " != "
                    Exit Select
                Case CodeBinaryOperatorType.IdentityEquality, CodeBinaryOperatorType.ValueEquality
                    str3 = " == "
                    Exit Select
                Case CodeBinaryOperatorType.BitwiseOr
                    str3 = " | "
                    Exit Select
                Case CodeBinaryOperatorType.BitwiseAnd
                    str3 = " & "
                    Exit Select
                Case CodeBinaryOperatorType.BooleanOr
                    str3 = " || "
                    Exit Select
                Case CodeBinaryOperatorType.BooleanAnd
                    str3 = " && "
                    Exit Select
                Case CodeBinaryOperatorType.LessThan
                    str3 = " < "
                    Exit Select
                Case CodeBinaryOperatorType.LessThanOrEqual
                    str3 = " <= "
                    Exit Select
                Case CodeBinaryOperatorType.GreaterThan
                    str3 = " > "
                    Exit Select
                Case CodeBinaryOperatorType.GreaterThanOrEqual
                    str3 = " >= "
                    Exit Select
                Case Else
                    Dim exception3 As New NotSupportedException(String.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, New Object() { childExpr.[Operator].ToString }))
                    exception3.Data.Item("ErrorObject") = childExpr
                    Throw exception3
            End Select
            Dim left As CodeExpression = childExpr.Left
            Dim right As CodeExpression = childExpr.Right
            If (childExpr.[Operator] = CodeBinaryOperatorType.ValueEquality) Then
                Dim expression5 As CodePrimitiveExpression = [TryCast](right,CodePrimitiveExpression)
                If (Not expression5 Is Nothing) Then
                    Dim obj2 As Object = expression5.Value
                    If (((Not obj2 Is Nothing) AndAlso (obj2.GetType Is GetType(Boolean))) AndAlso Not CBool(obj2)) Then
                        Dim expression6 As CodeBinaryOperatorExpression = [TryCast](left,CodeBinaryOperatorExpression)
                        If ((expression6 Is Nothing) OrElse (expression6.[Operator] <> CodeBinaryOperatorType.ValueEquality)) Then
                            flag = RuleDecompiler.MustParenthesize(left, parentExpression)
                            If flag Then
                                stringBuilder.Append("(")
                            End If
                            stringBuilder.Append("!")
                            RuleExpressionWalker.Decompile(stringBuilder, left, New CodeCastExpression)
                            If flag Then
                                stringBuilder.Append(")")
                            End If
                            Return
                        End If
                        str3 = " != "
                        left = expression6.Left
                        right = expression6.Right
                    End If
                End If
            ElseIf (childExpr.[Operator] = CodeBinaryOperatorType.Subtract) Then
                Dim expression7 As CodePrimitiveExpression = [TryCast](left,CodePrimitiveExpression)
                If ((Not expression7 Is Nothing) AndAlso (Not expression7.Value Is Nothing)) Then
                    Dim obj3 As Object = expression7.Value
                    Dim typeCode As TypeCode = Type.GetTypeCode(obj3.GetType)
                    Dim flag2 As Boolean = False
                    Select Case typeCode
                        Case TypeCode.Int32
                            flag2 = (CInt(obj3) = 0)
                            Exit Select
                        Case TypeCode.Int64
                            flag2 = (CLng(obj3) = 0)
                            Exit Select
                        Case TypeCode.Single
                            flag2 = (CSng(obj3) = 0!)
                            Exit Select
                        Case TypeCode.Double
                            flag2 = (CDbl(obj3) = 0)
                            Exit Select
                        Case TypeCode.Decimal
                            flag2 = (CDec(obj3) = 0)
                            Exit Select
                    End Select
                    If flag2 Then
                        flag = RuleDecompiler.MustParenthesize(right, parentExpression)
                        If flag Then
                            stringBuilder.Append("(")
                        End If
                        stringBuilder.Append("-")
                        RuleExpressionWalker.Decompile(stringBuilder, right, New CodeCastExpression)
                        If flag Then
                            stringBuilder.Append(")")
                        End If
                        Return
                    End If
                End If
            End If
            flag = RuleDecompiler.MustParenthesize(childExpr, parentExpression)
            If flag Then
                stringBuilder.Append("(")
            End If
            RuleExpressionWalker.Decompile(stringBuilder, left, childExpr)
            stringBuilder.Append(str3)
            RuleExpressionWalker.Decompile(stringBuilder, right, childExpr)
            If flag Then
                stringBuilder.Append(")")
            End If
        End Sub

        Friend Overrides Function Evaluate(ByVal expression As CodeExpression, ByVal execution As RuleExecution) As RuleExpressionResult
            Dim obj5 As Object
            Dim expression2 As CodeBinaryOperatorExpression = DirectCast(expression, CodeBinaryOperatorExpression)
            Dim operandValue As Object = RuleExpressionWalker.Evaluate(execution, expression2.Left).Value
            Dim [operator] As CodeBinaryOperatorType = expression2.[Operator]
            Select Case [operator]
                Case CodeBinaryOperatorType.BooleanAnd
                    If CBool(operandValue) Then
                        Return New RuleLiteralResult(RuleExpressionWalker.Evaluate(execution, expression2.Right).Value)
                    End If
                    Return New RuleLiteralResult(False)
                Case CodeBinaryOperatorType.BooleanOr
                    If CBool(operandValue) Then
                        Return New RuleLiteralResult(True)
                    End If
                    Return New RuleLiteralResult(RuleExpressionWalker.Evaluate(execution, expression2.Right).Value)
            End Select
            Dim obj6 As Object = RuleExpressionWalker.Evaluate(execution, expression2.Right).Value
            Dim info As RuleBinaryExpressionInfo = [TryCast](execution.Validation.ExpressionInfo(expression2),RuleBinaryExpressionInfo)
            If (info Is Nothing) Then
                Dim exception As New InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Messages.ExpressionNotValidated, New Object(0  - 1) {}))
                exception.Data.Item("ErrorObject") = expression2
                Throw exception
            End If
            Dim methodInfo As MethodInfo = info.MethodInfo
            If (Not methodInfo Is Nothing) Then
                If (methodInfo Is Literal.ObjectEquality) Then
                    obj5 = (operandValue Is obj6)
                Else
                    Dim parameters As ParameterInfo() = methodInfo.GetParameters
                    Dim objArray As Object() = New Object() { Executor.AdjustType(info.LeftType, operandValue, parameters(0).ParameterType), Executor.AdjustType(info.RightType, obj6, parameters(1).ParameterType) }
                    obj5 = methodInfo.Invoke(Nothing, objArray)
                End If
            Else
                obj5 = BinaryExpression.EvaluateBinaryOperation(expression2, info.LeftType, operandValue, [operator], info.RightType, obj6)
            End If
            Return New RuleLiteralResult(obj5)
        End Function

        <SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")> _
        Private Shared Function EvaluateBinaryOperation(ByVal binaryExpr As CodeBinaryOperatorExpression, ByVal lhsType As Type, ByVal lhsValue As Object, ByVal operation As CodeBinaryOperatorType, ByVal rhsType As Type, ByVal rhsValue As Object) As Object
            Dim literal As Literal
            Dim literal2 As Literal
            Dim literal3 As ArithmeticLiteral
            Dim literal4 As ArithmeticLiteral
            Dim exception As RuleEvaluationException
            Select Case operation
                Case CodeBinaryOperatorType.Add
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.Add(literal4)
                Case CodeBinaryOperatorType.Subtract
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.Subtract(literal4)
                Case CodeBinaryOperatorType.Multiply
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.Multiply(literal4)
                Case CodeBinaryOperatorType.Divide
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.Divide(literal4)
                Case CodeBinaryOperatorType.Modulus
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.Modulus(literal4)
                Case CodeBinaryOperatorType.IdentityInequality
                    Return (Not lhsValue Is rhsValue)
                Case CodeBinaryOperatorType.IdentityEquality
                    Return (lhsValue Is rhsValue)
                Case CodeBinaryOperatorType.ValueEquality
                    literal = Literal.MakeLiteral(lhsType, lhsValue)
                    If (literal Is Nothing) Then
                        Exit Select
                    End If
                    literal2 = Literal.MakeLiteral(rhsType, rhsValue)
                    If (literal2 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal.Equal(literal2)
                Case CodeBinaryOperatorType.BitwiseOr
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.BitOr(literal4)
                Case CodeBinaryOperatorType.BitwiseAnd
                    literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue)
                    If (literal3 Is Nothing) Then
                        Exit Select
                    End If
                    literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue)
                    If (literal4 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal3.BitAnd(literal4)
                Case CodeBinaryOperatorType.LessThan
                    literal = Literal.MakeLiteral(lhsType, lhsValue)
                    If (literal Is Nothing) Then
                        Exit Select
                    End If
                    literal2 = Literal.MakeLiteral(rhsType, rhsValue)
                    If (literal2 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal.LessThan(literal2)
                Case CodeBinaryOperatorType.LessThanOrEqual
                    literal = Literal.MakeLiteral(lhsType, lhsValue)
                    If (literal Is Nothing) Then
                        Exit Select
                    End If
                    literal2 = Literal.MakeLiteral(rhsType, rhsValue)
                    If (literal2 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal.LessThanOrEqual(literal2)
                Case CodeBinaryOperatorType.GreaterThan
                    literal = Literal.MakeLiteral(lhsType, lhsValue)
                    If (literal Is Nothing) Then
                        Exit Select
                    End If
                    literal2 = Literal.MakeLiteral(rhsType, rhsValue)
                    If (literal2 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal.GreaterThan(literal2)
                Case CodeBinaryOperatorType.GreaterThanOrEqual
                    literal = Literal.MakeLiteral(lhsType, lhsValue)
                    If (literal Is Nothing) Then
                        Exit Select
                    End If
                    literal2 = Literal.MakeLiteral(rhsType, rhsValue)
                    If (literal2 Is Nothing) Then
                        Exit Select
                    End If
                    Return literal.GreaterThanOrEqual(literal2)
                Case Else
                    exception = New RuleEvaluationException(String.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, New Object() { operation.ToString }))
                    exception.Data.Item("ErrorObject") = binaryExpr
                    Throw exception
            End Select
            exception = New RuleEvaluationException(String.Format(CultureInfo.CurrentCulture, Messages.BinaryOpFails, New Object() { operation.ToString, RuleDecompiler.DecompileType(lhsType), RuleDecompiler.DecompileType(rhsType) }))
            exception.Data.Item("ErrorObject") = binaryExpr
            Throw exception
        End Function

        Friend Overrides Function Match(ByVal expression As CodeExpression, ByVal comperand As CodeExpression) As Boolean
            Dim expression2 As CodeBinaryOperatorExpression = DirectCast(expression, CodeBinaryOperatorExpression)
            Dim expression3 As CodeBinaryOperatorExpression = DirectCast(comperand, CodeBinaryOperatorExpression)
            Return (((expression2.[Operator] = expression3.[Operator]) AndAlso RuleExpressionWalker.Match(expression2.Left, expression3.Left)) AndAlso RuleExpressionWalker.Match(expression2.Right, expression3.Right))
        End Function

        <SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")> _
        Private Shared Function PromotionPossible(ByVal type As Type, ByVal expression As CodeExpression) As Boolean
            If (type Is GetType(Integer)) Then
                Dim expression2 As CodePrimitiveExpression = [TryCast](expression,CodePrimitiveExpression)
                If (Not expression2 Is Nothing) Then
                    Dim num As Integer = CInt(expression2.Value)
                    Return (num >= 0)
                End If
            ElseIf (type Is GetType(Long)) Then
                Dim expression3 As CodePrimitiveExpression = [TryCast](expression,CodePrimitiveExpression)
                If (Not expression3 Is Nothing) Then
                    Dim num2 As Long = CLng(expression3.Value)
                    Return (num2 >= 0)
                End If
            End If
            Return False
        End Function

        <SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")> _
        Friend Overrides Function Validate(ByVal expression As CodeExpression, ByVal validation As RuleValidation, ByVal isWritten As Boolean) As RuleExpressionInfo
            Dim error As ValidationError
            Dim newParent As CodeBinaryOperatorExpression = DirectCast(expression, CodeBinaryOperatorExpression)
            If Not validation.PushParentExpression(newParent) Then
                Return Nothing
            End If
            If isWritten Then
                [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, New Object() { GetType(CodeBinaryOperatorExpression).ToString }), &H17A)
                [error].UserData.Item("ErrorObject") = newParent
                validation.Errors.Add([error])
            End If
            Dim info As RuleExpressionInfo = Nothing
            Dim info2 As RuleExpressionInfo = Nothing
            If (newParent.Left Is Nothing) Then
                [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.NullBinaryOpLHS, New Object() { newParent.[Operator].ToString }), &H541)
                [error].UserData.Item("ErrorObject") = newParent
                validation.Errors.Add([error])
            Else
                If TypeOf newParent.Left Is CodeTypeReferenceExpression Then
                    [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, New Object() { newParent.Left.GetType.FullName }), &H548)
                    [error].UserData.Item("ErrorObject") = newParent.Left
                    validation.AddError([error])
                    Return Nothing
                End If
                info = RuleExpressionWalker.Validate(validation, newParent.Left, False)
            End If
            If (newParent.Right Is Nothing) Then
                [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.NullBinaryOpRHS, New Object() { newParent.[Operator].ToString }), &H543)
                [error].UserData.Item("ErrorObject") = newParent
                validation.Errors.Add([error])
            Else
                If TypeOf newParent.Right Is CodeTypeReferenceExpression Then
                    [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, New Object() { newParent.Right.GetType.FullName }), &H548)
                    [error].UserData.Item("ErrorObject") = newParent.Right
                    validation.AddError([error])
                    Return Nothing
                End If
                info2 = RuleExpressionWalker.Validate(validation, newParent.Right, False)
            End If
            validation.PopParentExpression
            Dim info3 As RuleBinaryExpressionInfo = Nothing
            If ((Not info Is Nothing) AndAlso (Not info2 Is Nothing)) Then
                Dim expressionType As Type = info.ExpressionType
                Dim rhs As Type = info2.ExpressionType
                Select Case newParent.[Operator]
                    Case CodeBinaryOperatorType.Add, CodeBinaryOperatorType.Subtract, CodeBinaryOperatorType.Multiply, CodeBinaryOperatorType.Divide, CodeBinaryOperatorType.Modulus, CodeBinaryOperatorType.BitwiseOr, CodeBinaryOperatorType.BitwiseAnd
                        info3 = ArithmeticLiteral.ResultType(newParent.[Operator], expressionType, newParent.Left, rhs, newParent.Right, validation, [error])
                        If (info3 Is Nothing) Then
                            If (((Not expressionType Is GetType(UInt64)) OrElse Not BinaryExpression.PromotionPossible(rhs, newParent.Right)) AndAlso ((Not rhs Is GetType(UInt64)) OrElse Not BinaryExpression.PromotionPossible(expressionType, newParent.Left))) Then
                                [error].UserData.Item("ErrorObject") = newParent
                                validation.Errors.Add([error])
                            Else
                                info3 = New RuleBinaryExpressionInfo(expressionType, rhs, GetType(UInt64))
                            End If
                        End If
                        goto Label_060C
                    Case CodeBinaryOperatorType.IdentityInequality, CodeBinaryOperatorType.IdentityEquality
                        info3 = New RuleBinaryExpressionInfo(expressionType, rhs, GetType(Boolean))
                        goto Label_060C
                    Case CodeBinaryOperatorType.ValueEquality
                        info3 = Literal.AllowedComparison(expressionType, newParent.Left, rhs, newParent.Right, newParent.[Operator], validation, [error])
                        If (info3 Is Nothing) Then
                            If (((Not expressionType Is GetType(UInt64)) OrElse Not BinaryExpression.PromotionPossible(rhs, newParent.Right)) AndAlso ((Not rhs Is GetType(UInt64)) OrElse Not BinaryExpression.PromotionPossible(expressionType, newParent.Left))) Then
                                [error].UserData.Item("ErrorObject") = newParent
                                validation.Errors.Add([error])
                            Else
                                info3 = New RuleBinaryExpressionInfo(expressionType, rhs, GetType(Boolean))
                            End If
                        End If
                        goto Label_060C
                    Case CodeBinaryOperatorType.BooleanOr, CodeBinaryOperatorType.BooleanAnd
                        info3 = New RuleBinaryExpressionInfo(expressionType, rhs, GetType(Boolean))
                        If (Not expressionType Is GetType(Boolean)) Then
                            [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.LogicalOpBadTypeLHS, New Object() { newParent.[Operator].ToString, If((expressionType Is GetType(NullLiteral)), Messages.NullValue, RuleDecompiler.DecompileType(expressionType)) }), &H542)
                            [error].UserData.Item("ErrorObject") = newParent
                            validation.Errors.Add([error])
                            info3 = Nothing
                        End If
                        If (Not rhs Is GetType(Boolean)) Then
                            [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.LogicalOpBadTypeRHS, New Object() { newParent.[Operator].ToString, If((rhs Is GetType(NullLiteral)), Messages.NullValue, RuleDecompiler.DecompileType(rhs)) }), &H544)
                            [error].UserData.Item("ErrorObject") = newParent
                            validation.Errors.Add([error])
                            info3 = Nothing
                        End If
                        goto Label_060C
                    Case CodeBinaryOperatorType.LessThan, CodeBinaryOperatorType.LessThanOrEqual, CodeBinaryOperatorType.GreaterThan, CodeBinaryOperatorType.GreaterThanOrEqual
                        info3 = Literal.AllowedComparison(expressionType, newParent.Left, rhs, newParent.Right, newParent.[Operator], validation, [error])
                        If (info3 Is Nothing) Then
                            If (((Not expressionType Is GetType(UInt64)) OrElse Not BinaryExpression.PromotionPossible(rhs, newParent.Right)) AndAlso ((Not rhs Is GetType(UInt64)) OrElse Not BinaryExpression.PromotionPossible(expressionType, newParent.Left))) Then
                                [error].UserData.Item("ErrorObject") = newParent
                                validation.Errors.Add([error])
                            Else
                                info3 = New RuleBinaryExpressionInfo(expressionType, rhs, GetType(Boolean))
                            End If
                        End If
                        goto Label_060C
                End Select
                [error] = New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, New Object() { newParent.[Operator].ToString }), &H548)
                [error].UserData.Item("ErrorObject") = newParent
                validation.Errors.Add([error])
            End If
        Label_060C:
            If (Not info3 Is Nothing) Then
                Dim methodInfo As MethodInfo = info3.MethodInfo
                If (methodInfo Is Nothing) Then
                    Return info3
                End If
                Dim customAttributes As Object() = methodInfo.GetCustomAttributes(GetType(RuleAttribute), True)
                If ((customAttributes Is Nothing) OrElse (customAttributes.Length <= 0)) Then
                    Return info3
                End If
                Dim stack As New Stack([Of] MemberInfo)
                stack.Push(methodInfo)
                Dim flag As Boolean = True
                Dim attribute As RuleAttribute
                For Each attribute In customAttributes
                    If Not attribute.Validate(validation, methodInfo, methodInfo.DeclaringType, methodInfo.GetParameters) Then
                        flag = False
                    End If
                Next
                stack.Pop
                If Not flag Then
                    Return Nothing
                End If
            End If
            Return info3
        End Function

    End Class
End Namespace

